package com.freeseed.model.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.freeseed.model.entity.MajorDtl;
import com.freeseed.model.mapper.MajorDtlMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Allwayz
 * @since 2020-03-20
 */
@Slf4j
@RestController
@RequestMapping("major-dtls")
public class MajorDtlController {
    @Autowired
    private MajorDtlMapper majorDtlMapper;

    @GetMapping
    public List<MajorDtl> getMajorDtlList(){
        List<MajorDtl> majorDtlList = majorDtlMapper.selectList(new QueryWrapper<>());
        return majorDtlList;
    }

    @GetMapping("{Id}")
    public MajorDtl getMajorDtlById(@PathVariable int Id){
        MajorDtl majorDtl = majorDtlMapper.selectById(Id);
        return majorDtl;
    }

    @PostMapping
    public MajorDtl addMajorDtl(MajorDtl majorDtl){
        majorDtlMapper.insert(majorDtl);
        return majorDtl;
    }

    @PutMapping
    public MajorDtl updateMajorDtl(MajorDtl majorDtl){
        majorDtlMapper.update(majorDtl,new UpdateWrapper<MajorDtl>().eq("major_dtl_id",majorDtl.getMajorDtlId()));
        return majorDtl;
    }

    @DeleteMapping("{Id}")
    public void deleteMajorDtlById(@PathVariable int Id){
        majorDtlMapper.deleteById(Id);
    }
}
